<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>缓冲器</title>
</head>
<body>
    <button id="btn">点击执行</button>
    <div id="text"></div>
<script src="../js/retarder.js"></script>
<script>
    'use strict';
    // 定义缓冲器
    let retarder = new Retarder(function (value, retar) {
        textEl.innerHTML += '<p>' + value + '</p>'
        setTimeout(() => {
            retar.complete()
        }, 5000)
    }, function () {
            alert('执行中')
        }
    )

    // 元素
    let btnEl = document.getElementById('btn')
    let textEl = document.getElementById('text')
    // 点击事件
    btnEl.addEventListener('click', function () {
        retarder.emit(Math.random())
    })
</script>
</body>
</html>